import { createSlice, PayloadAction } from '@reduxjs/toolkit'

// // 是不是PC端
const isPc = window.innerWidth > 700

export const initialOffState = {
  /**
   * 是否为PC模式
   */
  isPc,
  /**
   * 否为编辑状态
   */
  edit: false,
  /**
   * 登录窗口弹框
   */
  login: false,
  /**
   * 壁纸设置
   */
  editWallpaper: false,
  /**
   * 页面列表&分页
   */
  editPage: false,
  /**
   * 顶部搜索
   */
  searchTopSwitch: false,
  /**
 * 设置菜单
 */
  settingMenu: false
}

export const offSlice = createSlice({
  name: 'off',
  initialState: initialOffState,
  reducers: {
    update: (state, actions: PayloadAction<Partial<typeof initialOffState>>) => {
      state = {
        ...state,
        ...actions.payload,
        isPc: window.innerWidth > 700
      } as typeof initialOffState
      return state
    },
  },
})

export const offActions = offSlice.actions

export const offReducer = offSlice.reducer

export type OffType = typeof initialOffState

